package com.billy.ohos.swipe.refresh;

import com.billy.ohos.swipe.ResourceTable;
import com.billy.ohos.swipe.SmartSwipeRefresh;
import ohos.agp.components.AttrSet;
import ohos.app.Context;

/**
 * classic footer for {@link SmartSwipeRefresh}
 *
 * @author billy.qi
 */
public class ClassicFooter extends ClassicHeader implements SmartSwipeRefresh.SmartSwipeRefreshFooter {

    public boolean mNoMoreData;

    public ClassicFooter(Context context) {
        super(context);
    }

    public ClassicFooter(Context context, AttrSet attrs) {
        super(context, attrs);
    }


    @Override
    public void onProgress(boolean dragging, float progress) {
        if (mNoMoreData) {
            cancelAnimation();
            return;
        }
        if (dragging) {
            setText(progress >= 1 ? ResourceTable.String_ssr_footer_release : ResourceTable.String_ssr_footer_pulling);
        } else if (progress <= 0) {
            cancelAnimation();
        }
    }

    @Override
    public long onFinish(boolean success) {
        cancelAnimation();
        if (!mNoMoreData) {
            setText(success ? ResourceTable.String_ssr_footer_finish : ResourceTable.String_ssr_footer_failed);
        }
        return 500;
    }

    @Override
    public void onDataLoading() {
        if (!mNoMoreData) {
            showAnimation();
            setText(ResourceTable.String_ssr_footer_refreshing);
        }
    }


    @Override
    public void setNoMoreData(boolean noMoreData) {
        this.mNoMoreData = noMoreData;
        if (noMoreData) {
            setText(ResourceTable.String_ssr_footer_no_more_data);
        }
    }
}
